home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 November / EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso / earcd / ead / ead29.dms / ead29.adf / Listati / Decigel020.asm < prev    next >
Assembly Source File  |  1991-04-08  |  3KB  |  142 lines

  1. **
  2. **
  3. **  Decigel020    - The functionality of the famous "decigel" program, but
  4. **  working on the 68020/68030 processors.
  5. **
  6. **  The old Decigel would correctly patch the instruction on the 68020,
  7. **  but chances are the old (bad) instruction was still in the instruction
  8. **  cache.  This code flushes the cache after modifying memory.
  9. **
  10. **  This code may not function under future revisions of the operating
  11. **  system.  This code is safe on the 68000/68010/68020 and 68030.
  12. **  This code is not expected to function on the 68040.  This code may
  13. **  be called from the CLI only.
  14. **
  15. **
  16. **  Written Tuesday 03-Apr-90 21:21:47 -Bryce Nesbitt
  17. **
  18. **
  19.         INCLUDE "exec/types.i"
  20.         INCLUDE "exec/memory.i"
  21.         INCLUDE "exec/ables.i"
  22.         INCLUDE "exec/execbase.i"
  23.         INCLUDE "libraries/dosextens.i"
  24.  
  25.         INT_ABLES
  26.  
  27.         XREF    _LVOFindTask
  28.         XREF    _LVOSupervisor
  29.  
  30. ABSEXECBASE    EQU 4
  31. PrivTrapVector    EQU $20
  32.  
  33.  
  34.  
  35.  
  36. ;-------------- install patch then detach -----------------------------------
  37.  
  38.         move.l    ABSEXECBASE,a6
  39.  
  40.  
  41.         ;
  42.         ;   Contents of the old vector are used to self-modify our
  43.         ;   code.  The new vector replaces the old.
  44.         ;
  45.         DISABLE
  46.         move.l    PrivTrapVector,ModifyCode+2
  47.         bsr.s    FlushCache
  48.         move.l    #NewPrivTrap,PrivTrapVector
  49.         ENABLE
  50.  
  51.  
  52.         ;
  53.         ;   Detach our code from the CLI
  54.         ;
  55.         suba.l    a1,a1
  56.         jsr    _LVOFindTask(a6)
  57.         move.l    d0,a0
  58.         move.l    pr_CLI(a0),a0
  59.         add.l    a0,a0
  60.         add.l    a0,a0
  61.         move.l    a0,d0
  62.         beq.s    not_cli
  63.         clr.l    cli_Module(a0)
  64. not_cli:    moveq    #0,d0
  65.         rts
  66.  
  67.  
  68.  
  69.  
  70. *
  71. *   Flush the instruction cache
  72. *
  73. FlushCache:    movem.l a5/a6,-(sp)
  74.         move.l    ABSEXECBASE,a6
  75.         btst.b    #AFB_68020,AttnFlags+1(a6)  ;>=68020 includes cache
  76.         beq.s    fc_nocache
  77.  
  78.         lea.l    FlushTrap(pc),a5
  79.         jsr    _LVOSupervisor(a6)
  80.  
  81. fc_nocache:    movem.l (sp)+,a5/a6
  82.         rts
  83. ;
  84. ;
  85. FlushTrap:    dc.w    $4e7a,$0002 ;movec.l CACR,d0
  86.         bset    #3,d0        ;Set "Clear instruction cache" bit
  87.         dc.w    $4e7b,$0002 ;movec.l d0,CACR
  88.         rte
  89.  
  90.  
  91.  
  92.  
  93.  
  94. *****************************************************************************
  95. **                                       **
  96. **                                       **
  97. **  The trap handler wedged into the privilege violation vector.       **
  98. **                                       **
  99. **  If the instruction was MOVE SR,<ea> it is converted to MOVE CCR,<ea>.  **
  100. **  The instruction cache is flushed, then the instruction is re-executed. **
  101. **                                       **
  102. **                                       **
  103. *****************************************************************************
  104.  
  105. STKOFFSET    EQU    4*3
  106.  
  107. ;
  108. ;   New privilege violation vector
  109. ;
  110. NewPrivTrap:    movem.l d0/a0/a6,-(sp)
  111.         move.l    STKOFFSET+2(sp),a0
  112.         move.w    (a0),d0             ; Examine opcode
  113.         andi.w    #~%111111,d0        ; Mask out EA field
  114.         cmpi.w    #$40C0,d0        ; A MOVE SR,<ea>?
  115.         beq.s    GotOne
  116.         movem.l (sp)+,d0/a0/a6
  117. ModifyCode:    jmp    $01234567        ; To previous handler... (exit)
  118.  
  119. ;
  120. ;   Code executed if the instruction was MOVE SR,<ea>
  121. ;
  122. GotOne:     move.l    ABSEXECBASE,a6
  123.  
  124.  
  125.         DISABLE
  126.         bset    #1,(a0)             ; Convert to MOVE CCR,<ea>
  127.         btst.b    #AFB_68020,AttnFlags+1(a6)  ;>=68020 includes cache
  128.         beq.s    no_cache
  129.  
  130.         dc.w    $4e7b,$8802 ; movec.l a0,CAAR
  131.         dc.w    $4e7a,$0002 ; movec.l CACR,d0
  132.         bset    #2,d0        ; Set "Clear entry in instruction cache"
  133.         dc.w    $4e7b,$0002 ; movec.l d0,CACR
  134. no_cache:    ENABLE
  135.  
  136.  
  137.         movem.l (sp)+,d0/a0/a6
  138.         rte                ; Rerun new opcode... (exit)
  139.  
  140.  
  141.         END
  142.